<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="../layui/css/layui.css">
    <script src="../layui/layui.js"></script>
    <script src="../jQuery/jquery-1.11.2.js"></script>
    <style type="text/css">
        #rl div div {
            width: 40px;
            float: left;
            height: 30px;

        }

        #rl div span {
            cursor: pointer;
        }

        .yi {
            float: left;
            border: 1px solid #009688;
            margin-left: 20px;
            margin-top: 20px;
            width: 280px;
            height: 250px;

        }

        .bt {
            background: #009688;
            /*background: rgba(1, 1, 1, 0.1);*/
            border: 1px solid rgba(1, 1, 1, 0.1);
            font: 26px 黑体;

        }

        i {
            width: 60px;
            height: 60px;
        }
    </style>
    <link rel="stylesheet" type="text/css" href="/css/font.css">
</head>
<body>
<div style="border:1px solid rgba(1,1,1,0.1);width:1250px;height: 900px;margin-left: 100px">
    <div style="width:1250px; height: 30px;" align="center"><i id="jian" style="font-size: 25px;margin-right: 360px"
                                                               class="layui-icon layui-icon-prev"></i><span
            style="font-size: 30px" id="nian"></span><i style="font-size: 25px;margin-left: 360px" id="jia"
                                                        class="layui-icon layui-icon-next"></i></div>
    <div style="width:1360px;height: 800px;" id="rl">
    </div>
</div>
<script>
    layui.use("layer",function () {

    var j = 0;
    var jt = new Date();
    var jts = "";
    var kkl = "";
    var sj = "";
    var jjr = "";

    /*var jjr=[{holidaydate:"2021-1-1",days:3,enddate:"4-1月-2021",id:"1"},
        {holidayde:"2021-2-11",days:7,enddate:"",id:"2"},
        {holidaydate:"2021-4-3",days:3,enddate:"",id:"3"},
        {holidaydate:"2021-5-1",days:5,enddate:"",id:"4"},
        {holidaydate:"2021-6-12",days:3,enddate:"",id:"5"},
        {holidaydate:"2021-9-19",days:3,enddate:"",id:"6"},
        {holidaydate:"2021-10-1",days:7,enddate:"",id:"7"}];*/
    $(function () {
        sj = jt.getFullYear();
        $("#nian").html(sj);
        jts = 1 + "-" + 1 + "-" + sj;
        kkl = new Date(Date.parse(jts));
        f(kkl);
        /* var ck="#"+jt.getFullYear()+"-"+(jt.getMonth()+1)+"-"+jt.getDate();
         $(ck).children('span').attr("class","layui-badge-dot layui-bg-green");
         $(ck).children('span').attr("style","width: 25px;height: 25px;font: 15px 黑体;");
*/
    })

    function f(dts) {
        var ss = "";
        for (var i = 1; i <= 12; i++) {
            ss += "<div class='yi'><div class='bt' style='width:280px;height:30px;float: none;' align='center'>" + i + "月</div><div name='ri'  align='center'>日</div><div name='yi' align='center'>一</div><div name='er' align='center'>二</div><div name='san' align='center'>三</div><div name='si' align='center'>四</div><div name='wu' align='center'>五</div><div name='lu' align='center'>六</div>";
            if (i == 1 || i == 3 || i == 5 || i == 7 || i == 8 || i == 10 || i == 12) {
                j = 31;
            } else if (i == 2) {
                if (dts.getFullYear() % 4 == 0 || dts.getFullYear() % 100 == 0) {
                    j = 29;
                } else {
                    j = 28;
                }
            } else {
                j = 30;
            }
            for (var k = 1; k <= j; k++) {
                var sl = i + "-" + k + "-" + dts.getFullYear();
                var dd = new Date(Date.parse(sl));
                var sk = dd.getFullYear() + "-" + i + "-" + k;
                if (dd.getDate() == 1) {
                    var x = dd.getDay() * 40;
                    var y = 0;
                    ss += "<div id='" + sk + "'align='center' style='margin-top:" + y + "px;margin-left:" + x + "px;'><span name='星期" + dd.getDay() + "' style='width: 20px;height: 20px;' >" + k + "</span></div>";
                } else {
                    ss += "<div id='" + sk + "' align='center'><span name='星期" + dd.getDay() + "' style='width: 20px;height: 20px;' >" + k + "</span></div>";
                }
            }
            ss += "</div>";
        }
        $("#rl").html(ss);
        for (var m = 0; m < document.getElementsByName("星期0").length; m++) {
            document.getElementsByName("星期0")[m].setAttribute("class", "layui-badge-dot");
            document.getElementsByName("星期0")[m].setAttribute("style", "width: 26px;height: 26px;font: 16px 黑体;");
        }
        for (var m = 0; m < document.getElementsByName("星期6").length; m++) {
            document.getElementsByName("星期6")[m].setAttribute("class", "layui-badge-dot");
            document.getElementsByName("星期6")[m].setAttribute("style", "width: 28px;height: 28px;font: 16px 黑体;");
        }
        $.ajax({
            url: "/dy/da",
            method: "get",
            success: function (msg) {
                var ck = "#" + jt.getFullYear() + "-" + (jt.getMonth() + 1) + "-" + jt.getDate();
                $(ck).children('span').attr("class", "layui-badge-dot layui-bg-green");
                $(ck).children('span').attr("style", "width: 25px;height: 25px;font: 15px 黑体;");
                jjr = msg;
                for (var s = 0; s < jjr.length; s++) {
                    var jjm = new Date(Date.parse(jjr[s].holidaydate));
                    var mmn = jjm.getMinutes() + 1;
                    var xc = 0;
                    if (mmn == 1 || mmn == 3 || mmn == 5 || mmn == 7 || mmn == 8 || mmn == 10 || mmn == 12) {
                        xc = 31;
                    } else if (mmn == 2) {
                        if (jjm.getFullYear() % 4 == 0 || dts.getFullYear() % 100 == 0) {
                            xc = 29;
                        } else {
                            xc = 28;
                        }
                    } else {
                        xc = 30;
                    }
                    for (var l = 0; l < jjr[s].days; l++) {
                        var bb = jjm.getDate();
                        var oo = jjm.getMonth() + 1;
                        var qq = jjm.getFullYear();
                        bb += l;
                        var xxz = "#" + qq + "-" + oo + "-" + bb;
                        $(xxz).children('span').attr("class", "layui-badge-dot layui-bg-dot");
                        $(xxz).children('span').attr("style", "width: 25px;height: 25px;font: 15px 黑体;");
                        if (jjm.getDay() == xc) {
                            oo += 1;
                            bb = 1;
                        }
                    }

                }
            }
        });

        $("#rl div span").each(function (a, e) {
            if ($(e).attr("name") != "星期0" && $(e).attr("name") != "星期6") {
                $(this).click(function () {
                    var vv = new Date(Date.parse($(this).parent().attr("id")));
                    if ($(this).attr('class') == "layui-badge-dot layui-bg-dot") {
                        layer.confirm('是否取消休假日', {
                            skin: 'layui-layer-molv' //样式类名
                            , closeBtn: 2
                            , anim: 6 ,//动画类型
                            btn: ['确定','取消'] //按钮
                        }, function(){
                            for (var i = 0; i < jjr.length; i++) {
                                var qaz = new Date(Date.parse(jjr[i].holidaydate));
                                var sjsx = qaz.getTime() + (60 * 60 * 1000 * 24) * (jjr[i].days - 1);
                                if (vv.getTime() >= (qaz.getTime() - 60 * 60 * 24 * 1000) && vv.getTime() <= sjsx) {
                                    $.ajax({
                                        url: "/dy/da/" + jjr[i].id,
                                        method: "delete",
                                        success: function (msg) {
                                            if (msg == "cg") {
                                                window.location.reload();
                                            } else {
                                                alert("失败");
                                            }
                                        }

                                    });
                                    break;
                                }
                            }

                        });

                    } else {
                        layer.confirm('是否设为休假日', {
                            skin: 'layui-layer-molv' //样式类名
                            , closeBtn: 2
                            , anim: 6 ,//动画类型
                            btn: ['确定','取消'] //按钮
                        }, function(){
                            layer.prompt({title: '放假天数', anim: 2 , formType: 3} , function(value, index, elem){
                                layer.closeAll();
                                var sks = value;
                                var xcx = vv.getTime() + 60 * 60 * 1000 * 24 * sks;
                                var iim = new Date(xcx);
                                var mzx = vv.getFullYear() + "-" + (vv.getMonth() + 1) + "-" + vv.getDate();
                                var mzxs = iim.getFullYear() + "-" + (iim.getMonth() + 1) + "-" + iim.getDate();

                                var zxk = {"holidaydate": mzx, "days": sks, "enddate": mzxs, "id": ""};
                                $.ajax({
                                    url: "/dy/das",
                                    method: "put",
                                    data: JSON.stringify(zxk),
                                    contentType: "application/json;charset=utf-8",
                                    success: function (msg) {
                                        if (msg == "cg") {
                                            window.location.reload();
                                        } else {
                                            alert("失败");
                                        }
                                    }
                                });
                            });
                        });
                      /*  layer.alert('墨绿风格，点击确认看深蓝', {
                            skin: 'layui-layer-molv' //样式类名
                            , closeBtn: 0
                            , anim: 3 //动画类型
                        },function () {



                        });*/


                    }

                });

            }

        });

    }

    $("i").each(function (a, e) {
        $(this).click(function () {
            if (($(e).get(0).id) == 'jian') {
                sj -= 1;
                $("#nian").html(sj);
                jts = 1 + "-" + 1 + "-" + sj;
                kkl = new Date(Date.parse(jts));
                f(kkl);
            } else {
                sj += 1;
                $("#nian").html(sj);
                jts = 1 + "-" + 1 + "-" + sj;
                kkl = new Date(Date.parse(jts));
                f(kkl);
            }
        });

    });
    /*
           $("#2021-1-2").children('span').attr("style","width: 25px;height: 25px;font: 15px 黑体;");

    */
    /*
           $("#2021-1-5").attr("style","background:#01AAED;");
    */
    });
</script>
</body>
</html>